package com.eclink.asset.asset.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.eclink.asset.asset.domain.dao.AssetItem;
import com.eclink.asset.asset.domain.dao.AssetMaintenance;
import com.eclink.asset.asset.domain.dto.AssetItemWithMaintenanceDTO;
import com.eclink.asset.asset.service.AssetMaintenanceService;
import com.eclink.asset.pojo.query.AssetItemQuery;
import com.ruoyi.common.core.controller.BaseController;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

import org.springframework.data.domain.Pageable;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * 资产清单表Controller
 *
 * @author chenshixian
 * @date 2024-09-12
 */
@Api(tags ="资产维修接口")
@RestController
@RequestMapping("/asset/maintenance")
public class AssetMaintenanceController extends BaseController {

    @Resource
    private AssetMaintenanceService service;

    @ApiOperation("查询列表")
    @PostMapping("/list")
    public ResponseEntity<Page<AssetItemWithMaintenanceDTO>> list(@RequestBody AssetItemQuery query, Pageable page) {
        Page<AssetItemWithMaintenanceDTO> list = service.selectList(query, page);
        return ResponseEntity.ok(list);
    }

    @ApiOperation("维保详情")
    @GetMapping("/detail/{id}")
    public ResponseEntity<AssetMaintenance> detail(@PathVariable Long id) {
        AssetMaintenance entity = service.selectById(id);
        return ResponseEntity.ok(entity);
    }

    @ApiOperation("保存")
    @PostMapping("/save/{itemId}")
    public ResponseEntity<Integer> save(@PathVariable Long itemId, @RequestBody AssetMaintenance entity) {

        service.save(itemId, entity);
        return ResponseEntity.ok(1);
    }


}
